*12345678901234567890123456789012345678901234567890123456789012345678901234567890

capture log close
clear
clear matrix
set mem 500m
set more off

#delimit ;

log using "C:\Documents and Settings\James\Desktop\my dropbox\ptas\baccinidata\bacciniACLP_match2.log", 
replace;

*	************************************************************************ *;
* 	File-Name: bacciniACLP_match2.do										 *;
*	Date:  12/31/10															 *;
*	Author: 	James Hollyer                                                *;
*	Purpose:   To merge the matching weights generated from the collapsed 	 *;
*	Baccini dataset in R with the full dataset and then re-run models on the *;
*	matched data.														 	 *;
*	Data Input: baccinimatched.dta, baccini_survival2.dta					 *;
*	************************************************************************ *;

use "c:\documents and settings\james\desktop\my dropbox\ptas\baccinidata\baccinimatchedACLP.dta";

sort leadid;

saveold "c:\documents and settings\james\desktop\my dropbox\ptas\baccinidata\baccinimatchedACLP.dta",
replace;

clear;

*	************************************************************************ *;
*	The following will merge the weights from the matched dataset with the   *;
*	baccini_survival2.dta dataset.  										 *;
*	************************************************************************ *;

use "c:\documents and settings\james\desktop\my dropbox\ptas\baccinidata\baccini_survival2.dta";

sort leadid year;

merge m:1 leadid using "c:\documents and settings\james\desktop\my dropbox\ptas\baccinidata\baccinimatchedACLP.dta";

drop if _merge~=3;

*As should be the case, all observations in the matched dataset are in the master;
*dataset.  The reverse is obviously not true.  Drop "pruned" observations from;
*the data.;

drop _merge;

*	************************************************************************ *;
*	The following will stset the data adjusting for the weights with which   *;
*	each observation is measured.											 *;
*	************************************************************************ *;

stset endobs [pweight=weights], id(leadid) fail(fail==1) origin(eindate) 
enter(time mdy(1,1,1995)) scale(365.25); 

*	************************************************************************ *;
*	The following will re-run the main models from the preliminary 			 *;
*	regressions.															 *;
*	************************************************************************ *;

gen log_num_pta_sign=.;
replace log_num_pta_sign=ln(num_pta_lead_sign+1);

gen pta_sign_dem = pta_lead_sign*democracy;
gen pta_num_dem = log_num_pta_sign*democracy;

stcox  log_num_pta_sign democracy pta_num_dem rgdpch openk grgdpch;

*Note that shared frailty estimates are not possible when using probability;
*weights, as is necessary after genetic matching.  May want to use a;
*nearest neighbor matching algorithm instead.  Genetic as an alternative;
*robustness check.;

stcox  log_num_pta_sign democracy rgdpch openk grgdpch;


clear;

use "c:\documents and settings\james\desktop\my dropbox\ptas\baccinidata\baccinimatchedACLP2.dta";

sort leadid;

saveold "c:\documents and settings\james\desktop\my dropbox\ptas\baccinidata\baccinimatchedACLP2.dta",
replace;

clear;

*	************************************************************************ *;
*	The following will merge the weights from the matched dataset with the   *;
*	baccini_survival2.dta dataset.  										 *;
*	************************************************************************ *;

use "c:\documents and settings\james\desktop\my dropbox\ptas\baccinidata\baccini_survival2.dta";

sort leadid year;

merge m:1 leadid using "c:\documents and settings\james\desktop\my dropbox\ptas\baccinidata\baccinimatchedACLP2.dta";

drop if _merge~=3;

*As should be the case, all observations in the matched dataset are in the master;
*dataset.  The reverse is obviously not true.  Drop "pruned" observations from;
*the data.;

drop _merge;

stset endobs, id(leadid) fail(fail==1) origin(eindate) 
enter(time mdy(1,1,1995)) scale(365.25); 

*	************************************************************************ *;
*	The following will re-run the main models from the preliminary 			 *;
*	regressions.															 *;
*	************************************************************************ *;

gen log_num_pta_sign=.;
replace log_num_pta_sign=ln(num_pta_lead_sign+1);

gen pta_sign_dem = pta_lead_sign*democracy;
gen pta_num_dem = log_num_pta_sign*democracy;

stcox  log_num_pta_sign democracy pta_num_dem rgdpch openk grgdpch, shared(ccode);

sum log_num_pta_sign;

local max_log_pta=r(max);
local max_pta_min_ACLP=0;
local max_pta_max_ACLP=`max_log_pta';

stcurve, hazard at1(democracy=0  log_num_pta_sign=0  pta_num_dem=0) 
at2(democracy=0 log_num_pta_sign=0.693 pta_num_dem=-0) 
at3(democracy=0 log_num_pta_sign=`max_log_pta' pta_num_dem = `max_pta_min_ACLP')
graphregion(fcolor(white)) ytitle(Hazard Rate) xtitle(Years in Office) 
scheme(s2mono) legend(label(1 No PTA) label(2 One PTA) label(3 Max PTAs)) 
name(minACLP, replace) subtitle(Autocracies);

stcurve, hazard at1(democracy=1  log_num_pta_sign=0  pta_num_dem=0) 
at2(democracy=1 log_num_pta_sign=0.693 pta_num_dem=.693) 
at3(democracy=1 log_num_pta_sign=`max_log_pta' pta_num_dem =`max_pta_max_ACLP')
graphregion(fcolor(white)) ytitle(Hazard Rate) xtitle(Years in Office) 
scheme(s2mono) legend(label(1 No PTA) label(2 One PTA) label(3 Max PTAs)) 
name(maxACLP, replace) subtitle(Democracies);

graph combine minACLP maxACLP, ycommon graphregion(fcolor(white))
title(Estimated Hazard Rates);


 
*	************************************************************************ *;
*	The following will close the log file.									 *;
*	************************************************************************ *;

log close;
